/**
 * Author: Dmitry Ustimov
 * Date: 6/1/13
 * Time: 10:08 PM
 */

package com.gmail.dmitryustimov.ms.java7.chain_of_responsibility.classic.work.demo.handlers1_100_requests10;

import java.math.BigDecimal;

public class CocreteHandler1 extends Handler {

    private String name;
    protected int level;
    private BigDecimal sum = BigDecimal.valueOf(0);

    public CocreteHandler1(String name, int level) {
        this.level = level;
        this.name = name;
    }

    @Override
    public void doAction(Request request) {
        if (request instanceof Request1) {
            doAction((Request1)request);
        }
        if (request instanceof Request2) {
            doAction((Request2)request);
        }
        if (request instanceof Request3) {
            doAction((Request3)request);
        }
        if (request instanceof Request4) {
            doAction((Request4)request);
        }
        if (request instanceof Request5) {
            doAction((Request5)request);
        }
        if (request instanceof Request6) {
            doAction((Request6)request);
        }
        if (request instanceof Request7) {
            doAction((Request7)request);
        }
        if (request instanceof Request8) {
            doAction((Request8)request);
        }
        if (request instanceof Request9) {
            doAction((Request9)request);
        }
        if (request instanceof Request10) {
            doAction((Request10)request);
        }
    }

    public void doAction(Request1 request) {
        sum.add(BigDecimal.valueOf(1));
    }
    public void doAction(Request2 request) {
        sum.add(BigDecimal.valueOf(2));
    }
    public void doAction(Request3 request) {
        sum.add(BigDecimal.valueOf(3));
    }
    public void doAction(Request4 request) {
        sum.add(BigDecimal.valueOf(4));
    }
    public void doAction(Request5 request) {
        sum.add(BigDecimal.valueOf(5));
    }
    public void doAction(Request6 request) {
        sum.add(BigDecimal.valueOf(6));
    }
    public void doAction(Request7 request) {
        sum.add(BigDecimal.valueOf(7));
    }
    public void doAction(Request8 request) {
        sum.add(BigDecimal.valueOf(8));
    }
    public void doAction(Request9 request) {
        sum.add(BigDecimal.valueOf(9));
    }
    public void doAction(Request10 request) {
        sum.add(BigDecimal.valueOf(10));
    }

    @Override
    public Boolean canHandle(Request request) {
        return request.getRequestLevel() <= level;
    }
}
